<%@ page import="model.*, java.util.*"%>
<%
Paper p = (Paper) request.getAttribute("paper");
ChoiceQuestion[] qlist = (ChoiceQuestion[]) request.getAttribute("question[]");
ChoiceQuestion[] nlist = (ChoiceQuestion[]) request.getAttribute("unadded_question[]");
@SuppressWarnings("unchecked")
HashMap<Integer, Integer> qpoint = (HashMap<Integer, Integer>) request.getAttribute("qpoint");
%>
<%@ include file="header.tpl.jsp"%>

<form action="#" method="post">

<div class="box">
	<h2>Paper Information</h2>
	<%if(p.getPid() > 0){%>
	<div class="head_actions">
		<a href="EditPaper?pid=<%=p.getPid()%>&updatescore=1">[Update Total Point]</a>
	</div>
	<%}%>

	<table>
		<tr><th><label for="title">Paper Title:</label></th><td><input type="text" id="title" name="title" value="<%=p.getTitle()%>" /></td></tr>
		<tr><th><label for="totalscore">Total Point:</label></th><td><input type="text" id="totalscore" name="totalscore" value="<%=p.getTotalScore()%>" readonly="readonly" /> point(s)</td></tr>
		<tr><th><label for="timeout">Timeout:</label></th><td><input type="text" id="timeout" name="timeout" value="<%=p.getTimeout()%>" /> second(s)</td></tr>
	</table>
</div>

<%if(p.getPid() > 0){%>
<div class="box list">
	<h2>Existing Questions</h2>
	<div class="head_actions">
		<a href="EditQuestion?pid=<%=p.getPid()%>">[Add a New Question]</a>
	</div>
	<table>
		<thead>
			<tr><td>Question Content</td><td>Point</td><td>Operation</td></tr>
		</thead>
		<tbody>
		<%for(int i = 0; i < qlist.length; i++){%>
		<%ChoiceQuestion q = qlist[i];%>
			<tr>
				<td><%=q.getContent()%></td>
				<td><input type="text" name="qpoint[<%=q.getQid()%>]" value="<%=qpoint.get(q.getQid())%>" size="2" /></td>
				<td>
					<a href="EditQuestion?pid=<%=p.getPid()%>&qid=<%=q.getQid()%>">[Edit]</a>
					<a href="EditPaper?pid=<%=p.getPid()%>&removeqid=<%=q.getQid()%>">[Remove]</a>
				</td>
			</tr>
		<%}%>
		</tbody>
	</table>
</div>
<%}%>

<%if(p.getPid() > 0){%>
<div class="box list">
	<h2>Not Added Questions</h2>
	<table>
		<thead>
			<tr><td>Question Content</td><td>Operation</td></tr>
		</thead>
		<tbody>
		<%for(int i = 0; i < nlist.length; i++){%>
		<%ChoiceQuestion q = nlist[i];%>
			<tr>
				<td><%=q.getContent()%></td>
				<td>
					<a href="EditPaper?pid=<%=p.getPid()%>&addqid=<%=q.getQid()%>">[Add]</a>
				</td>
			</tr>
		<%}%>
		</tbody>
	</table>
</div>
<%}%>


<div class="post_buttons">
	<button type="submit">Complete And Submit</button>
	<button type="button" onclick="location.href='DeletePaper?pid=<%=p.getPid()%>';">Delete Paper</button>
</div>

</form>

<%@ include file="footer.tpl.jsp"%>